using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.UIElements;

public class SpawnScripts : MonoBehaviour
{
    public float SpawnTime = 0.3f;

    public GameObject prefab;

    public Vector3 DoorPosition;

    void Start()
    {
        DoorPosition = transform.position;

        NavMeshHit hit;
        if(NavMesh.SamplePosition(DoorPosition,out hit,1.0f,NavMesh.AllAreas)){
            DoorPosition = hit.position;
        }
        else{
            Debug.LogError("No NavMesh found near the target position.");
        }
    }

    void Update()
    {
        SpawnTime -= Time.deltaTime;
        if(SpawnTime <= 0){
            Instantiate(prefab,DoorPosition,Quaternion.identity);
            SpawnTime = 0.3f;
        }
    }


}
